package com.lanqiao.guimei.listener;

import com.lanqiao.web.mvc.Configuration;
import com.lanqiao.web.mvc.ControllerMapping;
import org.apache.log4j.Logger;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Map;

/**
 * @author stone(huangshizhang) at 2019-08-12 15:48
 */
public class AppConfigurationListener implements ServletContextListener {


    static Logger logger = Logger.getLogger(AppConfigurationListener.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        logger.info("初始化ServletContextListener实例");

        Map<String, ControllerMapping> controllerMappingMap = new Configuration().config();
        ServletContext servletContext = sce.getServletContext();
        servletContext.setAttribute("com.lanqiao.guimei.controller", controllerMappingMap);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        logger.info("销毁ServletContext实例");
    }
}
